﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.Utils;


namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class PR_SalaryCommandDetail : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        private ICommandBLL cmdBLL = new CommandBLL();
        private ICommandDetailBLL dcmdBLL = new CommandDetailBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            IncludeJava();

            if (!IsPostBack)
            {
                lblID.Text = Request.QueryString["cmd_seq"];
                LoadDataGrid();
                BindLabel();
            }
            
        }
        public void IncludeJava()
        {
            HtmlGenericControl script = new HtmlGenericControl();
            script.TagName = "script";
            script.Attributes.Add("type", "text/javascript");
            script.Attributes.Add("src", "../../Scripts/jsfunction.js");
            Page.Header.Controls.Add(script);
        }

        private void LoadDataGrid()
        {
            try
            {
                DataSet ds = new DataSet();
                DataTable dt = new DataTable();

                ds = dcmdBLL.LoadCommandDetails((int?)null, Convert.ToInt32(lblID.Text), (int?)null);
                dt = ds.Tables[0];

                RadGrid2.DataSource = dt;
                RadGrid2.DataBind();
            }
            catch (Exception ex)
            {
                Web.ShowAlert(this,ex.Message);
            }
        }
        private void BindLabel()
        {
            DataSet ds2 = new DataSet();
            DataTable dt2 = new DataTable();

            ds2 = cmdBLL.LoadCommands(SystemInfo._CmdEmployee, Convert.ToInt32(lblID.Text), (int?)null, (int?)null);
            dt2 = ds2.Tables[0];
            if (dt2.Rows.Count > 0)
            {
                lblCmdName.Text = dt2.Rows[0]["cmd_name"].ToString();
                lblRefNo.Text = dt2.Rows[0]["cmd_ref_no"].ToString();
                lblAppDate.Text = string.Format("{0:dd/MM/yyyy}", dt2.Rows[0]["approved_date"]);
            }
        }
        protected void RadGrid2_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            try
            {
                if (e.CommandName == "Delete")
                {
                    int seq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["cmd_dtls_seq"]);
                    dcmdBLL.Delete(seq, ssMng.EmpSeqI);
                }
                if (e.CommandName == "btnClick")
                {
                    return;
                }
                if (e.CommandName == "InsertSelect")
                {
                    dcmdBLL.InsertSalaryChangeAuto(Convert.ToInt32(lblID.Text), ssMng.EmpSeqI);
                }

                LoadDataGrid();
                
            }
            catch (Exception ex)
            {
                Web.ShowAlert(this, ex.Message);
            }

        }
    }
}
